<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title> 型号均价</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/common/jquery.global.settings.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
     <div class="easyui-container-fluid">
         <div class="easyui-panel" style="border:none;">
             <div class="nav" id="nav"></div>
             <div class="easyui-panel" style="border:none;">
                 <form id="ff">
                     <div style="margin-bottom:10px;">
                     	<span>
                         <label class="item-label" style="width: 50px;margin-left: 20px;">年份：</label>
                         <input type="text" class="easyui-combobox" name="year" id="year" style="width:100px;"/>
                     	</span>
                     	<span id="monthLabel">
	                         <label class="item-label" style="width: 50px;margin-left: 20px;">月份：</label>
	                         <input type="text" class="easyui-combobox" name="month" id="month" style="width:100px;"/></span>
                     	<span id="weekLabel">
	                         <label class="item-label" style="width: 50px;margin-left: 20px;">周数：</label>
	                         <input type="text" class="easyui-combobox" name="week" id="week" style="width:100px;"/></span>
                     	<label class="item-label" style="width: 50px;margin-left: 20px;">品类：</label>
		                <select id="categorySelect" name="categoryCode" class="easyui-combobox" style="width:100px;"></select>
                         <label class="item-label" style="width: 50px;margin-left: 20px;">品牌：</label>
                         <select id="brandSelect" name="brandCode" class="easyui-combobox" style="width:100px;">
                         </select>
                         <label class="item-label" style="width: 50px;margin-left: 20px;">排名：</label>
                         <input type="text" name="ranking" id="ranking" class="easyui-textbox"value="200" style="width:100px;" />
                         <label class="item-label" style="width: 80px;margin-left: 20px;">上月差值：</label>
                         <select name="czSymbol" id="comparatorD"  class="easyui-combobox" data-options="panelHeight:'165'" style="width:55px;"   >
                             <option value="EQUAL">=</option>
                             <option value="GREAT">></option>
                             <option value="GREAT_EQUAL">>=</option>
                             <option value="LITTLE"><</option>
                             <option value="LITTLE_EQUAL"><=</option>
                         </select>
                         <input type="text" name="difference"  class="easyui-textbox" style="width:80px;"/>
                         <label class="item-label" style="width: 80px;margin-left: 20px;">差值占比：</label>
                         <select  id="comparatorZb" name="comparatorZb" class="easyui-combobox" data-options="panelHeight:'165'" style="width:55px;"  data-options="
                                                        prompt: '填80代表80%',panelHeight:'150'"  >
                             <option value="EQUAL">=</option>
                             <option value="GREAT">></option>
                             <option value="GREAT_EQUAL">>=</option>
                             <option value="LITTLE"><</option>
                             <option value="LITTLE_EQUAL"><=</option>
                         </select>
                         <input type="text" name="percentage" id="percentage" class="easyui-textbox" style="width:80px;"/>
                         <label class="item-label" >商场码：</label>
                         <select id="mallComparer" name="mallComparer" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:50px;" prompt="比较符">
                             <option value="EQUAL" >=</option>
                             <option value="NOT_EQUAL" selected = "selected"><pre><></pre></option>
                         </select>
                         <input type="text" id="mallCode" name="mallCode" class="easyui-textbox" data-options="prompt: '多个用逗号隔开',panelHeight:'150'"
                                value="00006625" style="width:120px;" />
                         <div style="display:inline-block; margin-top:10px;" id="categorywrapper">
                             <label class="item-label" style="width: 50px;margin-left: 20px;">套餐：</label>
                             <select id="comboSyayus" name="comboSyayus" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;" prompt="比较符">
                                 <option value="ALL"  selected = "selected" >不限制</option>
                                 <option value="COMBO">套餐</option>
                                 <option value="NOCOMBO">非套餐</option>
                             </select>
                             <label class="item-label" >渠道码：</label>
                             <select id="channelComparer" name="channelComparer" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:55px;" prompt="比较符">
                                 <option value="EQUAL"  selected = "selected" >=</option>
                                 <option value="NOT_EQUAL"><pre><></pre></option>
                             </select>
                             <input type="text" id="channelSelect" name="channelCode" class="easyui-textbox" data-options="
                                                        prompt: '多个用逗号隔开',panelHeight:'150'" style="width:93px;"/>
                             <label class="item-label" style="width: 50px;margin-left: 20px;">规格：</label>
                             <input type="text" name="propCode" id="propCode" class="easyui-combobox" data-options="panelHeight:'150'" style="width:100px;" />
                             <select name="comparator" id="comparator"  class="easyui-combobox" data-options="panelHeight:'150'" style="width:100px;"   >
                                <option value="EQUAL">=</option>
                                <option value="GREAT">></option>
                                <option value="GREAT_EQUAL">>=</option>
                                <option value="LITTLE"><</option>
                                <option value="LITTLE_EQUAL"><=</option>
                                <option value="NOT_EQUAL"><></option>
                                <option value="CONTAIN">包含</option>
                             </select>
                             <div style="display: inline-block" id="metadatavalue" >
                             </div>
                             <label class="item-label" style="width: 100px;pxmargin-left: 20px;">拼抖快型号：</label>
                             <input id="isExcludePdkSpecial" class="easyui-switchbutton" checked style="width:90px;height:30px;" onText="排除" offText="不排除"  >
                             <label class="item-label" style="width: 100px;pxmargin-left: 20px;">当期独占型号：</label>
                             <input id="isShowExclusiveModel" class="easyui-switchbutton" style="width:90px;height:30px;" onText="开启" offText="关闭"  >
                         </div>
		                <a href="javascript:void(0);" style="margin-left:40px;width:80px;" class="easyui-linkbutton c8" onclick="searchBy()">查询</a>
                     </div>
                 </form>
             </div>
             <div class="table-wrapper">
                 <table id="datagrid" class="easyui-datagrid" data-options="fitColumns:true,scrollbarSize:0"  style="max-height: 698px;">
                     <thead>
                        <tr>
                            <th data-options="field:'brandName',align:'center'" width="120" formatter="formatBrand">品牌</th>
                            <th data-options="field:'modelName',align:'center'" width="120" formatter="formatModel">型号</th>
                            <th data-options="field:'0',align:'center'" width="90" formatter="formatCount_0">本月（周）</th>
                            <th data-options="field:'1',align:'center'" width="90" formatter="formatCount_1">-1月（周）</th>
                            <th data-options="field:'2',align:'center'" width="90" formatter="formatCount_2">-2月（周）</th>
                            <th data-options="field:'3',align:'center'" width="90" formatter="formatCount_3">-3月（周）</th>
                            <th data-options="field:'4',align:'center'" width="90" formatter="formatCount_4">-4月（周）</th>
                            <th data-options="field:'5',align:'center'" width="90" formatter="formatCount_5">去年同期</th>
                            <th data-options="field:'6',align:'center'" width="100" formatter="formatCount_01">与上月对比</th>
                            <th data-options="field:'7',align:'center'" width="100" formatter="formatCount_05">与去年对比</th>
                        </tr>
                     </thead>
                 </table>
             </div>
         </div>
     </div>
     <script type="text/javascript">
         $(function(){
             setNav();
             initUserCategorySelect("categorySelect",function (code) {
                 initModelSearchSelect("propCode","metadatavalue",code);
                 initBrandSelectC("brandSelect",null,null,code);
             });
             // initBrandSelect("brandSelect");
             initProvinceSelect("provinceSelect", provinceChange);
             initMonthWeek("monthLabel","weekLabel");
             $("#datagrid").datagrid({
                 // pagination:true,
                 rownumbers:true
             });
             aRecords("型号均价","/webapp/pages/product/audit/modelAvgprice")
         });
         function provinceChange(provinceCode){
             initCitySelect("citySelect", provinceCode);
             $.ajax({
                 url:config.url+'/dictionary/getCityByProvince/'+provinceCode,
                 type:"get",
                 xhrFields:{withCredentials:true},
                 success:function (data) {
                     if(data){
                         $(data).map(function(index,item){
                             item['text'] = item.name;
                         });
                         data.unshift({"text":"-请选择-","code":""});
                         $("#citySelect").combobox({
                             "textFiled":"text",
                             "valueField":"code",
                             "data":data
                         });
                     }
                 },
                 error:function(XMLHttpRequest,textStatus,errorThrown){
                 }
             })
         }

         function searchBy(){
        	 if(!$('#categorySelect').combobox('getValue')){
        		 alert('请选择品类');
        		 return;
        	 }
             var data1 = getFormData(document.getElementById("ff"));
             data1.reportType=window.parent.workMode.toUpperCase();
             data1.isExcludePdkSpecial = $("#isExcludePdkSpecial").switchbutton("options").checked ? 'true' : 'false';;
             data1.isShowExclusiveModel = $("#isShowExclusiveModel").switchbutton("options").checked ? 'true' : 'false';;
             $.ajax({
                  url:config.url + "/modelTop/avgPrice",
                  type:"GET",
                  data:transfer(data1),
                 dataType:'json',
                  xhrFields:{withCredentials:true},
                  beforeSend:function () {
                      $.messager.progress({
                          title:"请稍等",
                          interval:50,
                          text:"数据加载中..."
                      });
                    },
                  success:function(data){
                      $.messager.progress("close");
                      if (data.code && data.code == 515) {
                          $.messager.alert("提示", data.msg, "error");
                          return;
                      }
                      if (null != data && data.length > 0) {
                          $("#datagrid").datagrid({data: data}).datagrid("getPager");
                      } else {
                          $("#datagrid").datagrid({data: []}).datagrid("getPager");
                      }
                  },
                  error:function(data){
                     $.messager.progress("close");
                  }
              });
          }

        function formatBrand(val, row) {
 			return row.brandName + '(' + row.brandCode + ')';
 		}
 		function formatModel(val, row) {
 			return row.modelName + '(' + row.modelCode + ')';
 		}
		function formatCount_0(val, row) {
			return row.avgPriceList[0];
		}
		function formatCount_1(val, row) {
                return row.avgPriceList[1];
		}
		function formatCount_2(val, row) {
			return row.avgPriceList[2];
		}
		function formatCount_3(val, row) {
			return row.avgPriceList[3];
		}
		function formatCount_4(val, row) {
			return row.avgPriceList[4];
		}
		function formatCount_5(val, row) {
			return row.avgPriceList[5] ;
		}
		function formatCount_01(val, row) {
            var bq = row.avgPriceList[0]
            var sq = 0;
            if(row.avgPriceList[1]){
                sq = row.avgPriceList[1];
            }else if(row.avgPriceList[2]){
                sq = row.avgPriceList[2];
            }else if(row.avgPriceList[3]){
                sq = row.avgPriceList[3];
            }else if(row.avgPriceList[4]){
                sq = row.avgPriceList[4];
            }
            var zb=100;
            var zd='--';
            if(bq>sq){
                // zb=(Math.floor(((bq-sq)/bq)* 100) / 100)*100;
                zb=Math.floor(((bq-sq)/bq)* 100);
                return style('+' + ~~(bq-sq), 'yes') +"/"+zb+"%";
            }else if(bq<sq){
                // zb=(Math.floor(((sq-bq)/bq)* 100) / 100)*100;
                zb=Math.floor(((sq-bq)/bq)* 100);
                return style('-' + ~~(sq-bq), 'no')+"/"+zb+"%";
            }else{
                return '--';
            }

		}
		//用来核查占比 data1是查询前获取的值 data是查询返回的值
         function pdzb(data1,data) {
             var jg=[];
             if(data1.comparatorZb && data1.percentage){
                 data.forEach(function (row) {
                     var ty=false;//用来确定本条要不要
                     var bq = row.avgPriceList[0]
                     var sq = 0;
                     if(row.avgPriceList[1]){
                         sq = row.avgPriceList[1];
                     }else if(row.avgPriceList[2]){
                         sq = row.avgPriceList[2];
                     }else if(row.avgPriceList[3]){
                         sq = row.avgPriceList[3];
                     }else if(row.avgPriceList[4]){
                         sq = row.avgPriceList[4];
                     }
                     var zb=100;
                     if(bq>sq){
                         zb=((bq-sq)/bq)*100;
                     }else if(bq<sq){
                         zb=((sq-bq)/bq)* 100;
                     }else{
                         zb=0;
                     }
                     if(data1.comparatorZb =="EQUAL"){
                         if(zb==data1.percentage){
                             ty=true;
                         }
                     }else if(data1.comparatorZb =="GREAT"){
                         if(zb>data1.percentage){
                             ty=true;
                         }
                     }else if(data1.comparatorZb =="GREAT_EQUAL"){
                         if(zb>=data1.percentage){
                             ty=true;
                         }
                     } else if(data1.comparatorZb =="LITTLE"){
                         if(zb<data1.percentage){
                             ty=true;
                         }
                     }else if(data1.comparatorZb =="LITTLE_EQUAL"){
                         if(zb<=data1.percentage){
                             ty=true;
                         }
                     }
                     if(ty){
                         jg.push(row);
                     }
                 })

             }else{
                 jg=data;
             }
             return jg;
         }
		function formatCount_05(val, row) {
			if(row.avgPriceList[0]>row.avgPriceList[5]){

				return style('+' + ~~(row.avgPriceList[0]-row.avgPriceList[5]), 'yes');
			}else if(row.avgPriceList[0]<row.avgPriceList[5]){
				return style('-' + ~~(row.avgPriceList[5]-row.avgPriceList[0]), 'no');
			}else{
				return '--';
			}
		}
		function style(text, flag){
			if('yes'==flag){
				return '<span style="font-size: 14px;font-weight: bold;color: red;">' + text + '</span>';
			}else if('no'==flag){
				return '<span style="font-size: 14px;font-weight: bold;color: green;">' + text + '</span>';
			}
			return text;
		}
         function initChannelSelectshare(channelSelectId, mallSelectId, initCallback){
             var dtd = $.Deferred();
             $.ajax({
                 url:config.url +"/channel/getAll",
                 type:"get",
                 xhrFields:{withCredentials:true},
                 success:function (data) {
                     if(data){
                         data.unshift({"name":"-请选择-","code":"-请选择-","selected":true});
                         $("#"+channelSelectId).combobox({
                             "textField":"code",
                             "valueField":"code",
                             "panelHeight":"150",
                             "data":data
                         });
                         dtd.resolve();
                         // 回调函数
                         if(typeof initCallback === "function"){
                             if(data.length>=2){
                                 $("#"+channelSelectId).combobox('select', data[1]['code']);
                             }
                             initCallback();
                         }
                     }
                 },
                 error:function(XMLHttpRequest,textStatus,errorThrown){
                     dtd.reject();
                 }
             });
             return dtd.promise();
         }
         $("#ff").keydown(function (event) {
             var e = event || window.event;
             var keyCode = e.keyCode || e.which;
             if(keyCode=="13"){
                 searchBy();
             }
         });
     </script>
</body>
</html>